<template>
  <div>
    <pageHeader :title="title" back></pageHeader>
    <pageMain padding="0px" background="transparent">
      <chunkTitle title="添加数据">

        <template slot="header-right">

          <el-button type="primary">主要按钮</el-button>

        </template>

        <template>
          <el-form
            :model="addDictionaryValueForm"
            class="demo-form-inline"
          >
            <el-form-item label="数据">
              <el-input
                v-model="addDictionaryValueForm.label"
                placeholder="数据"
              ></el-input>
            </el-form-item>
            <el-form-item label="value">
              <el-input
                v-model="addDictionaryValueForm.value"
                placeholder="value"
              ></el-input>
            </el-form-item>
            <el-form-item label="允许修改">
              <el-switch
                v-model="addDictionaryValueForm.update"
                active-color="#13ce66"
                inactive-color="#ff4949"
              >
              </el-switch>
            </el-form-item>
            <el-form-item label="允许删除">
              <el-switch
                v-model="addDictionaryValueForm.remove"
                active-color="#13ce66"
                inactive-color="#ff4949"
              >
              </el-switch>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="addDicValue"
                >添加数据</el-button
              >
            </el-form-item>
          </el-form>
        </template>
      </chunkTitle>
      <chunkTitle title="字典数据">
        <template>
          <el-table :data="valusList">
            <el-table-column property="label" label="数据" align="left">
              <template slot-scope="scope">
                <el-input v-model="scope.row.label"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              property="value"
              width="90"
              label="value"
              align="center"
            >
              <template slot-scope="scope">
                <el-input
                  v-model="scope.row.value"
                  style="text-align: center"
                ></el-input>
              </template>
            </el-table-column>

            <el-table-column
              property="create_date"
              label="创建时间"
              align="center"
            >
            </el-table-column>
            <el-table-column label="操作" width="90" align="center">
              <template slot-scope="scope">
                <div class="overall-flex overall-table-options">
                  <el-link
                    type="danger"
                    size="mini"
                    plain
                    @click="removeDicValueButton(scope.row)"
                    >删除</el-link
                  >
                </div>
              </template>
            </el-table-column>
          </el-table>
        </template>
      </chunkTitle>
    </pageMain>
  </div>
</template>

<script>
import dictionaryAPI from "@/api/dictionary";
import chunkTitle from "@/components/chunk-title/chunk-title.vue";
import pageMain from "~/page-main/page-main.vue";
import pageHeader from "~/page-header/page-header.vue";
export default {
  components: {
    pageMain,
    pageHeader,
    chunkTitle,
  },
  data() {
    return {
      dic: null,
      title:"",

      // 字典内容列表数据
      valusList: [],
      // 添加数据表单
      addDictionaryValueForm: {
        label: "",
        value: "",
        comment:"",
        update: true,
        remove: true,
      },
    };
  },

  created() {
    let dic = this.$route.query.dic;
    let title = this.$route.query.title;
    this.dic = dic;
    this.title = "字典：" + title
    this.getDicValueList();
  },

  methods: {
    getDicValueList() {
      let dic_id = this.dic;
      dictionaryAPI.dictionaryValueList({ dic_id }).then((res) => {
        let data = res.data;
        this.valusList = data;
      });
    },
    // 新增字典内容
    addDicValue() {
      let dic_id = this.dic;
      let label = this.addDictionaryValueForm.label;
      let value = this.addDictionaryValueForm.value;
      let comment = this.addDictionaryValueForm.comment;
      let update = this.addDictionaryValueForm.update;
      let remove = this.addDictionaryValueForm.remove;
      dictionaryAPI
        .addDictionaryValue({ dic_id, label, value, comment, update, remove })
        .then((res) => {
          let { msg } = res;
          this.$message({
            message: msg,
            type: "success",
          });
          this.getDicValueList();
        })
        .catch((err) => {
          let { msg } = err;
          this.$message({
            message: msg,
            type: "error",
          });
        });
    },
  },
};
</script>

<style></style>
